import 'package:bitcoin_mine/common/global.dart';
import 'package:bitcoin_mine/controllers/animation_controller.dart'
    as balance_animation;
// import 'package:bitcoin_mine/widgets/rolling_number.dart';
import 'package:bitcoin_mine/widgets/rolling_number_units.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
// import '../controllers/home_controller.dart';

class HeaderSection extends StatelessWidget {
  const HeaderSection({super.key});

  @override
  Widget build(BuildContext context) {
    // final HomeController homeController = Get.find();
    final balance_animation.BalanceAnimationController controller =
        Get.find<balance_animation.BalanceAnimationController>();
    return Container(
      width: 320.w,
      margin: EdgeInsets.symmetric(vertical: 15.h),
      padding: EdgeInsets.symmetric(vertical: 10.h),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0x00000000), Color(0xFF0D91FF), Color(0x00000000)],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          // Bitcoin图标
          Image.asset(
            'assets/images/icon_bit_coin.png',
            width: 36.r,
            height: 36.r,
          ),
          const SizedBox(width: 16),
          // 余额信息
          Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Obx(() {
                final units = controller.displayBalanceUnits.value;
                return RollingNumberUnits(
                  units: units,
                  scale: 15, // 与动画控制器 _scale 保持一致
                  prefix: '',
                  suffix: '',
                  duration: const Duration(milliseconds: 800),
                  style: TextStyle(color: Colors.white, fontSize: 12.sp),
                );
              }),
              const SizedBox(height: 4),
              Obx(
                () => Text(
                  Global.btcPrice.value,
                  style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                    color: Colors.white,
                    fontSize: 12.sp,
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
